<style lang="less">
    @import '../../styles/common.less';
    @import '../../styles/table.less';
</style>

<template>
    <div>
        <Row class="margin-top-10">
            <Col span="24">
                <Card>
                    <p slot="title" style="height:25px;">
                        <Icon type="ios-keypad"></Icon> 产品回收站
                    </p>
                    <div>
                        <div>
                            <Table stripe :columns="columns" :data="rows" border></Table>
                        </div>
                    </div>
                </Card>
            </Col>
        </Row>
    </div>
</template>

<script>
    export default {
        name: 'getList',
        components: {
            // canEditTable //组件名称，需要import
        },
        data () {
            return {
                rows: [],
                columns: [
                    {
                        title: 'ID',
                        align: 'center',
                        key: 'goods_id',
                        width: 80,
                    }, {
                        title: '产品编号',
                        align: 'center',
                        key: 'goods_sn',
                        width: 150,
                    }, {
                        title: '产品名称',
                        align: 'center',
                        key: 'goods_name',
                        width: 150,
                    }, {
                        title: '图片',
                        align: 'center',
                        key: 'cover_img',
                        width: 150,
                        render: (h, params) => {
                            return h('img', {
                                attrs : {src : params.row.cover_img, style: 'height:50px;margin:5px;'}
                            });
                        }
                    }, {
                        title: '价格',
                        align: 'center',
                        key: 'price',
                        width: 80,
                        render: (h, params) => {
                            return params.row.price/100;
                        }
                    }, {
                        title: '市场价',
                        align: 'center',
                        key: 'market_price',
                        width: 80,
                        render: (h, params) => {
                            return params.row.market_price/100;
                        }
                    }, {
                        title: '排序',
                        align: 'center',
                        key: 'sort',
                        width: 80,
                    }, {
                        title: '销量',
                        align: 'center',
                        key: 'sales_num',
                        width: 150,
                    }, {
                        title: '点击量',
                        align: 'center',
                        key: 'click_count',
                        width: 150,
                    }, {
                        title: '上架状态',
                        align: 'center',
                        key: 'is_online',
                        width: 120,
                        render: (h, params) => {
                            return params.row.is_online==1?'上架':'下架'
                        }
                    }, {
                        title: '类型',
                        align: 'center',
                        key: 'is_real',
                        width: 120,
                        render: (h, params) => {
                            return params.row.is_real==1?'实物产品':'虚拟产品'
                        }
                    },

                    {
                        title: '操作',
                        key: 'action',
                        width: 200,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h('Button', {
                                    props: {type: 'primary', size: 'small'},
                                    style: {marginRight: '5px'},
                                    on: {
                                        click: () => {
                                            this.edit(params.row.goods_id)
                                        }
                                    }
                                }, '恢复'),
                            ]);
                        }
                    }
                ],
            };
        },
        methods: {
            getList() {
                this.$http.post('admin/goods/recycleList', this.$qs.stringify()).then((res) => {
                    var d = res.data;
                    if (d.code == 0) {
                        this.rows = d.data;
                    } else {
                        this.$Notice.error({
                            title: 'Error Warning',
                            desc: `Error：${d.msg}<br>`
                        });
                    }
                })
            },
            show (index) {
                this.$Modal.info({
                    title: 'User Info',
                    content: `Name：${this.rows[index].username}<br>
                        Address：${this.rows[index].email}`
                })
            },
            edit (goods_id) {
                this.$http.post('admin/goods/renew', this.$qs.stringify({goods_id:goods_id})).then((res) => {
                    var d = res.data;
                    if (d.code == 0) {
                        this.getList();
                    } else {
                        this.$Notice.error({
                            title: 'Error Warning',
                            desc: `Error：${d.msg}<br>`
                        });
                    }
                })
            },
        },
        created () {
            this.getList();
        }
    };
</script>
